<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>logtalk_load_context/2 &mdash; The Logtalk Handbook v3.93.0-b01 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=d75fae25" />
      <link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../../_static/css/custom.css?v=396eccfe" />

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../../_static/jquery.js?v=5d32c60e"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../../_static/documentation_options.js?v=c8100655"></script>
        <script src="../../_static/doctools.js?v=9a2dae69"></script>
        <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/js/theme.js"></script>
    <!-- begin favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
    <meta name="msapplication-TileColor" content="#355b95" />
    <meta name="theme-color" content="#ffffff" />
    <!-- end favicon -->
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Flags" href="flag_predicates.html" />
    <link rel="prev" title="logtalk_library_path/2" href="logtalk_library_path_2.html" />
   
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../../index.html" class="icon icon-home">
            The Logtalk Handbook
              <img src="../../_static/logtalk.gif" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.93.0
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
    
              <p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../userman/index.html">User Manual</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Reference Manual</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../grammar.html">Grammar</a></li>
<li class="toctree-l2"><a class="reference internal" href="../control/index.html">Control constructs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../directives/index.html">Directives</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Built-in predicates</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="enumerating_entity_predicates.html">Enumerating objects, categories and protocols</a></li>
<li class="toctree-l3"><a class="reference internal" href="enumerating_entity_property_predicates.html">Enumerating objects, categories and protocols properties</a></li>
<li class="toctree-l3"><a class="reference internal" href="creating_entity_predicates.html">Creating new objects, categories and protocols</a></li>
<li class="toctree-l3"><a class="reference internal" href="abolishing_entity_predicates.html">Abolishing objects, categories and protocols</a></li>
<li class="toctree-l3"><a class="reference internal" href="entity_relation_predicates.html">Objects, categories, and protocols relations</a></li>
<li class="toctree-l3"><a class="reference internal" href="event_handling_predicates.html">Event handling</a></li>
<li class="toctree-l3"><a class="reference internal" href="multi_threading_predicates.html">Multi-threading</a></li>
<li class="toctree-l3"><a class="reference internal" href="engine_predicates.html">Multi-threading engines</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="compiling_predicates.html">Compiling and loading source files</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="logtalk_compile_1.html"><code class="docutils literal notranslate"><span class="pre">logtalk_compile/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_compile_2.html"><code class="docutils literal notranslate"><span class="pre">logtalk_compile/2</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_load_1.html"><code class="docutils literal notranslate"><span class="pre">logtalk_load/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_load_2.html"><code class="docutils literal notranslate"><span class="pre">logtalk_load/2</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_make_0.html"><code class="docutils literal notranslate"><span class="pre">logtalk_make/0</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_make_1.html"><code class="docutils literal notranslate"><span class="pre">logtalk_make/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_make_target_action_1.html"><code class="docutils literal notranslate"><span class="pre">logtalk_make_target_action/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="logtalk_library_path_2.html"><code class="docutils literal notranslate"><span class="pre">logtalk_library_path/2</span></code></a></li>
<li class="toctree-l4 current"><a class="current reference internal" href="#"><code class="docutils literal notranslate"><span class="pre">logtalk_load_context/2</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="flag_predicates.html">Flags</a></li>
<li class="toctree-l3"><a class="reference internal" href="linter_predicates.html">Linter</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../methods/index.html">Built-in methods</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../tutorial/index.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devtools/index.html">Developer Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../libraries/index.html">Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ports/index.html">Ports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributions/index.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../bibliography.html">Bibliography</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../genindex.html">Index</a></li>
</ul>

    <p class="caption"><span class="caption-text">External Contents</span></p>
    <ul>
    <li class="toctree-l1"><a class="reference internal" href="../../../apis/index.html">APIs</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://logtalk.org">Logtalk website</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://github.com/LogtalkDotOrg/logtalk3">GitHub repo</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">The Logtalk Handbook</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Reference Manual</a></li>
          <li class="breadcrumb-item"><a href="index.html">Built-in predicates</a></li>
          <li class="breadcrumb-item"><a href="compiling_predicates.html">Compiling and loading source files</a></li>
      <li class="breadcrumb-item active"><code class="docutils literal notranslate"><span class="pre">logtalk_load_context/2</span></code></li>
      <li class="wy-breadcrumbs-aside">
              <a href="https://github.com/LogtalkDotOrg/logtalk3/blob/master/docs/handbook/sources/refman/predicates/logtalk_load_context_2.rst" class="fa fa-github"> Edit on GitHub</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <p class="align-right"><strong>built-in predicate</strong></p>
<section id="logtalk-load-context-2">
<span id="predicates-logtalk-load-context-2"></span><span id="index-0"></span><h1><code class="docutils literal notranslate"><span class="pre">logtalk_load_context/2</span></code><a class="headerlink" href="#logtalk-load-context-2" title="Link to this heading"></a></h1>
<section id="description">
<h2>Description<a class="headerlink" href="#description" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="k">logtalk_load_context</span>(<span class="nv">Key</span>, <span class="nv">Value</span>)
</pre></div>
</div>
<p>Provides access to the Logtalk compilation/loading context. The following keys
are currently supported:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">entity_identifier</span></code> - identifier of the entity being compiled if any</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">entity_prefix</span></code> - internal prefix for the entity compiled code</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">entity_type</span></code> - returns the value <code class="docutils literal notranslate"><span class="pre">module</span></code> when compiling a module as an object</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">entity_relation</span></code> - returns the entity relations as declared in the entity opening directive</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">source</span></code> - full path of the source file being compiled</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">file</span></code> - the actual file being compiled, different from <code class="docutils literal notranslate"><span class="pre">source</span></code> only when processing an <code class="docutils literal notranslate"><span class="pre">include/1</span></code> directive</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">basename</span></code> - source file basename</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">directory</span></code> - source file directory</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">stream</span></code> - input stream being used to read source file terms</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">target</span></code> - the full path of the intermediate Prolog file</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">flags</span></code> - the list of the explicit flags used for the compilation of the source file</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">term</span></code> - the source file term being compiled</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">term_position</span></code> - the position of the term being compiled (<code class="docutils literal notranslate"><span class="pre">StartLine-EndLine</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">variables</span></code> - the variables of the term being compiled (<code class="docutils literal notranslate"><span class="pre">[Variable1,</span> <span class="pre">...]</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">variable_names</span></code> - the variable names of the term being compiled (<code class="docutils literal notranslate"><span class="pre">[Name1=Variable1,</span> <span class="pre">...]</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">variable_names(Term)</span></code> - the variable names of the term being compiled (<code class="docutils literal notranslate"><span class="pre">[Name1=Variable1,</span> <span class="pre">...]</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">singletons</span></code> - the singleton variables of the term being compiled (<code class="docutils literal notranslate"><span class="pre">[Name1=Variable1,</span> <span class="pre">...]</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">singletons(Term)</span></code> - the singleton variables of the term being compiled (<code class="docutils literal notranslate"><span class="pre">[Name1=Variable1,</span> <span class="pre">...]</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">parameter_variables</span></code> - list of parameter variable names and positions (<code class="docutils literal notranslate"><span class="pre">[Name1-Position1,</span> <span class="pre">...]</span></code>)</p></li>
</ul>
<p>For the <code class="docutils literal notranslate"><span class="pre">entity_relation</span></code> key, the possible values are:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">extends_protocol(Protocol,</span> <span class="pre">ParentProtocol,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">implements_protocol(ObjectOrCategory,</span> <span class="pre">Protocol,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">extends_category(Category,</span> <span class="pre">ParentCategory,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">imports_category(Object,</span> <span class="pre">Category,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">extends_object(Prototype,</span> <span class="pre">Parent,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">instantiates_class(Instance,</span> <span class="pre">Class,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">specializes_class(Class,</span> <span class="pre">Superclass,</span> <span class="pre">Scope)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">complements_object(Category,</span> <span class="pre">Object)</span></code></p></li>
</ul>
<p>Calling this predicate with the <code class="docutils literal notranslate"><span class="pre">parameter_variables</span></code> key only succeeds
when compiling a parametric entity containing parameter variables.</p>
<p>This predicate is usually called by the <a class="reference internal" href="../methods/term_expansion_2.html#methods-term-expansion-2"><span class="std std-ref">term_expansion/2</span></a>
and <a class="reference internal" href="../methods/goal_expansion_2.html#methods-goal-expansion-2"><span class="std std-ref">goal_expansion/2</span></a> methods. It can also be called directly
from <a class="reference internal" href="../directives/initialization_1.html#directives-initialization-1"><span class="std std-ref">initialization/1</span></a> directives in a source file. Note
that the entity keys are only available when compiling an entity term or
from an object <code class="docutils literal notranslate"><span class="pre">initialization/1</span></code> directive.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The <code class="docutils literal notranslate"><span class="pre">term_position</span></code> key is only supported in
<a class="reference internal" href="../../glossary.html#term-backend-Prolog-compiler"><span class="xref std std-term">backend Prolog compilers</span></a>
that provide access to the start and end lines of a read term. When
such support is not available, the value <code class="docutils literal notranslate"><span class="pre">-1</span></code> is returned for both
the start and the end lines.</p>
<p>Variables in the values of the <code class="docutils literal notranslate"><span class="pre">term</span></code>, <code class="docutils literal notranslate"><span class="pre">variables</span></code>, <code class="docutils literal notranslate"><span class="pre">variable_names</span></code>,
and <code class="docutils literal notranslate"><span class="pre">singletons</span></code> keys are not shared with, respectively, the term and
goal arguments of the <code class="docutils literal notranslate"><span class="pre">term_expansion/2</span></code> and <code class="docutils literal notranslate"><span class="pre">goal_expansion/2</span></code> methods.
Use instead the <code class="docutils literal notranslate"><span class="pre">variable_names(Term)</span></code> and <code class="docutils literal notranslate"><span class="pre">singletons(Term)</span></code> keys.</p>
</div>
</section>
<section id="modes-and-number-of-proofs">
<h2>Modes and number of proofs<a class="headerlink" href="#modes-and-number-of-proofs" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="k">logtalk_load_context</span>(<span class="o">?</span>callable, <span class="o">-</span>nonvar) <span class="o">-</span> zero_or_more
</pre></div>
</div>
</section>
<section id="errors">
<h2>Errors<a class="headerlink" href="#errors" title="Link to this heading"></a></h2>
<div class="line-block">
<div class="line"><code class="docutils literal notranslate"><span class="pre">Key</span></code> is neither a variable nor a callable term:</div>
<div class="line-block">
<div class="line"><code class="docutils literal notranslate"><span class="pre">type_error(callable,</span> <span class="pre">Key)</span></code></div>
</div>
<div class="line"><code class="docutils literal notranslate"><span class="pre">Key</span></code> is a callable term but not a valid key:</div>
<div class="line-block">
<div class="line"><code class="docutils literal notranslate"><span class="pre">domain_error(logtalk_load_context_key,</span> <span class="pre">Key)</span></code></div>
</div>
</div>
</section>
<section id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="c">% expand source file terms only if they are entity terms</span>
<span class="k">term_expansion</span>(<span class="nv">Term</span>, <span class="nv">ExpandedTerms</span>) <span class="o">:-</span>
    <span class="k">logtalk_load_context</span>(entity_identifier, <span class="nv">_</span>),
    ....

<span class="c">% expand source file term while accessing its variable names</span>
<span class="k">term_expansion</span>(<span class="nv">Term</span>, <span class="nv">ExpandedTerms</span>) <span class="o">:-</span>
    <span class="k">logtalk_load_context</span>(variable_names(<span class="nv">Term</span>), <span class="nv">VariableNames</span>),
    ....

<span class="c">% define a library alias based on the source directory</span>
<span class="p">:- </span><span class="k">initialization</span>((
    <span class="k">logtalk_load_context</span>(directory, <span class="nv">Directory</span>),
    <span class="k">assertz</span>(<span class="k">logtalk_library_path</span>(my_app, <span class="nv">Directory</span>))
)).
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../methods/term_expansion_2.html#methods-term-expansion-2"><span class="std std-ref">term_expansion/2</span></a>,
<a class="reference internal" href="../methods/goal_expansion_2.html#methods-goal-expansion-2"><span class="std std-ref">goal_expansion/2</span></a>,
<a class="reference internal" href="../directives/initialization_1.html#directives-initialization-1"><span class="std std-ref">initialization/1</span></a></p>
</div>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="logtalk_library_path_2.html" class="btn btn-neutral float-left" title="logtalk_library_path/2" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="flag_predicates.html" class="btn btn-neutral float-right" title="Flags" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 1998-2025, Paulo Moura.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>